package com.ftg.learnmybatis.learnio;

import com.alibaba.druid.sql.visitor.functions.Char;
import org.omg.CORBA_2_3.portable.InputStream;

import java.io.*;
import java.util.Arrays;

/**
 * 字符流
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/3/13 上午10:41
 */
public class Example03 {
    public static void main(String[] args) {
        try(
                OutputStream out = new FileOutputStream("/home/kangjx/Desktop/abc2.txt");
                OutputStreamWriter write = new OutputStreamWriter(out);
                InputStreamReader reader = new FileReader("/home/kangjx/Desktop/abc.txt")
        ) {
            // 一次性把数据全部取出来- 缓存 缓冲区
            char[] cs = new char[100];

            int index = 0;
            while(reader.ready()){
                cs[index++] = (char)reader.read();
                if(index == cs.length){
                    write.write(cs);
                    index = 0;
                    //清空缓冲
                    Character c = null;
                    Arrays.fill(cs,c);
                }
            }
            if(index < cs.length && reader.read() == -1){
                write.write(cs);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

}
